import 'package:flutter/material.dart';
import 'package:flutter_rating_bar/flutter_rating_bar.dart';

class RatingBarScreen extends StatefulWidget{
  @override
  RatingBarState createState() => RatingBarState();
}

class RatingBarState extends State<RatingBarScreen>{
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('RatingBar展示效果'),
        centerTitle: true,
        titleSpacing: 10,
      ),

      body: Column(
        crossAxisAlignment: CrossAxisAlignment.center,

        children: <Widget>[
          ListTile(title: Text('默认效果'),),

          RatingBar(
              //初始化的选中星的个数
              initialRating: 4.5,
              //星星的排列顺序
              direction: Axis.horizontal,
              //是否允许半个星的显示
              allowHalfRating: false,
              //总共显示星的个数
              itemCount: 5,
              //星与星之间的间距
              itemPadding: EdgeInsets.symmetric(horizontal: 2.0),
              //显示的图标与选择的颜色
              itemBuilder: (context, index){
                return Icon(Icons.star, color: Colors.amber,);
              },
              //选择事件
              onRatingUpdate: (rating){
                setState(() {

                });
              }
          ),

          ListTile(title: Text('自定义显示图标'),),

          RatingBar(
            //初始化的选中星的个数
              initialRating: 4.5,
              //星星的排列顺序
              direction: Axis.horizontal,
              //是否允许半个星的显示
              allowHalfRating: true,
              //总共显示星的个数
              itemCount: 5,
              //星与星之间的间距
              itemPadding: EdgeInsets.symmetric(horizontal: 2.0),
              //自定义显示图标
              ratingWidget: RatingWidget(
                  full: Icon(Icons.star, color: Colors.amber,),
                  half: Icon(Icons.star_half, color: Colors.amber,),
                  empty: Icon(Icons.star_border, color: Colors.grey,)
              ),
              //选择事件
              onRatingUpdate: (rating){
                setState(() {

                });
              }
          )
        ],
      ),
    );
  }
}